﻿using DevExpress.XtraTreeList;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace Data
{

    /// <summary>
    /// 序列化结构
    /// </summary>
    [Newtonsoft.Json.JsonObject(Newtonsoft.Json.MemberSerialization.OptOut)]
    public class RequestParameteData : INotifyPropertyChanged
    {

        public event PropertyChangedEventHandler PropertyChanged;


        [Newtonsoft.Json.JsonIgnore]
        public TreeList _treeListBody { get; set; }


        /// <summary>
        /// 版本号
        /// </summary>
        private int _requestVersion = 1;
        public int requestVersion
        {
            get { return _requestVersion; }
            set
            {
                _requestVersion = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("requestVersion"));
                }
            }
        }


        /// <summary>
        /// 存储所有可选择的URL
        /// </summary>
        private List<ParameterItemNodeData> _urls = new List<ParameterItemNodeData>();
        public List<ParameterItemNodeData> urls
        {
            get { return _urls; }
            set
            {
                _urls = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("urls"));
                }
            }
        }

        /// <summary>
        /// 请求URL
        /// </summary>
        private string _requestUrl = "";
        public string requestUrl
        {
            get { return _requestUrl; }
            set
            {
                _requestUrl = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("requestUrl"));
                }
            }
        }

        /// <summary>
        /// 请求方式
        /// </summary>
        private string _requestType = "POST";
        /// <summary>
        /// 请求方式
        /// </summary>
        public string requestType
        {
            get { return _requestType; }
            set
            {
                _requestType = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("requestType"));
                }
            }
        }


        /// <summary>
        /// 请求代码
        /// </summary>
        private string _requestCode = "";
        public string requestCode
        {
            get { return _requestCode; }
            set
            {
                _requestCode = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("requestCode"));
                }
            }
        }

        /// <summary>
        /// 写入超时
        /// </summary>
        private int _requestWriteOutTime = 6000;
        public int requestWriteOutTime
        {
            get { return _requestWriteOutTime; }
            set
            {
                _requestWriteOutTime = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("requestWriteOutTime"));
                }
            }
        }

        /// <summary>
        /// 读取超时
        /// </summary>
        private int _requestReadOutTime = 6000;
        public int requestReadOutTime
        {
            get { return _requestReadOutTime; }
            set
            {
                _requestReadOutTime = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("requestReadOutTime"));
                }
            }
        }


        /// <summary>
        /// 存储所有的URL的Get信息
        /// </summary>
        private List<ParameterItemNodeData> _requestUrlget = new List<ParameterItemNodeData>();
        public List<ParameterItemNodeData> requestUrlget
        {
            get { return _requestUrlget; }
            set
            {
                _requestUrlget = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("requestUrlget"));
                }
            }
        }


        private List<ParameterItemNodeData> _requestHeads = new List<ParameterItemNodeData>();
        public List<ParameterItemNodeData> requestHeads
        {
            get { return _requestHeads; }
            set
            {
                _requestHeads = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("requestHeads"));
                }
            }
        }

        /// <summary>
        /// 存储所有Body
        /// </summary>
        private List<ParameterItemNodeData> _requestBody = new List<ParameterItemNodeData>();
        public List<ParameterItemNodeData> requestBody
        {
            get { return _requestBody; }
            set
            {
                _requestBody = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("requestBody"));
                }
            }
        }


        /// <summary>
        /// 存储所有Cookie
        /// </summary>
        private List<ParameterItemNodeData> _requestCookie = new List<ParameterItemNodeData>();
        public List<ParameterItemNodeData> requestCookie
        {
            get { return _requestCookie; }
            set
            {
                _requestCookie = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("requestCookie"));
                }
            }
        }


        /// <summary>
        /// 存储所有返回结果
        /// </summary>
        private List<ParameterItemNodeData> _requestReturn = new List<ParameterItemNodeData>();
        public List<ParameterItemNodeData> requestReturn
        {
            get { return _requestReturn; }
            set
            {
                _requestReturn = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("requestReturn"));
                }
            }
        }

        /// <summary>
        /// Form表单提交-文件
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public List<ParameterItemNodeData> requestForm = new List<ParameterItemNodeData>();
    }

    /// <summary>
    /// 序列化节点结构
    /// </summary>
    public class ParameterItemNodeData
    {
        /// <summary>
        /// key
        /// </summary>
        public string Key { get; set; }
        /// <summary>
        /// 值
        /// </summary>
        public string Value { get; set; }
        /// <summary>
        /// 类型
        /// </summary>
        public string Type { get; set; }
        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }
        
        /// <summary>
        /// 代码构建
        /// </summary>
        public string Parameter { get; set; }


        #region 节点目录结构一定要放置到最后

        /// <summary>
        /// 当前节点ID
        /// </summary>
        public string ID { get; set; }

        /// <summary>
        /// 父节点ID
        /// </summary>
        public string ParentID { get; set; }

        #endregion
    }
}
